<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增品牌间隔</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <div class="layui-form-item">
        <label class="layui-form-label required">品牌</label>
        <div class="layui-input-block">
            <select name="brandType" lay-filter="aihao" lay-verify="required" lay-reqtext="品牌是必填项，岂能为空？" id="brandType">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">开始日期</label>
        <div class="layui-input-block">
            <input type="text" name="startTime" id="startTime" lay-verify="required" lay-reqtext="开始日期是必填项，岂能为空？" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">结束日期</label>
        <div class="layui-input-block">
            <input type="text" name="endTime" id="endTime" autocomplete="off" lay-verify="required" lay-reqtext="结束日期是必填项，岂能为空？" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认</button>
        </div>
    </div>
    </div>
</div>

<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$;

        laydate.render({
            elem: '#startTime',
            type: 'datetime'
        });
        laydate.render({
            elem: '#endTime',
            type: 'datetime'
        });

        $.ajax({
            type: "get",
            url: "/zxjy/enum/brandtype",
            headers: {
                'Authorization': layui.data("Authorization")['Authorization'],
            },
            success: function (result) {
                if (result.state === 200) {
                    for (obj of result.result) {
                            $("#brandType").append("<option value=\"" + obj.key + "\">" + obj.value + "</option>");
                    }
                    //重新渲染
                    layui.form.render("select");
                }
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data);
            $.ajax({
                type: "POST",
                url: "/zxjy/brand/add/supervisor",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                headers: {
                    'Authorization': layui.data("Authorization")['Authorization'],
                },
                success: function (result) {
                    if (result.state === 200) {
                        parent.layui.table.reload("currentTableId");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }
                }
            });

        });

    });
</script>
</body>
</html>
